﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>修改密码</title>
    <link href="~/Content/layui/css/layui.css" rel="stylesheet" />
    <link href="~/Content/layui/css/reset.css" rel="stylesheet" />

    <style>
        .loginMain {
            background: rgba(255, 255, 255, 0.33);
            position: absolute;
            left: 50%;
            top: 50%;
            z-index: 1;
            width: 782px;
            height: 445px;
            padding: 15px;
            margin-left: -396px;
            margin-top: -255px;
            border-radius: 4px;
            background-color: #F2F2F2;
        }
    </style>
</head>
<body>
    <div class="loginMain">
        <div style="border-bottom: 1px solid rgba(255, 255, 255, 0.33);">
            <h1 style="color: #666;font-weight: bold;text-align: center;font-size: 35px;margin-bottom: 20px;margin-top: 10px;">
                修改密码
            </h1>
            <h3 style="color: #ff0000;font-weight: bold;text-align: center;font-size: 15px;margin-bottom: 20px;margin-top: 10px;">
                初次登陆或者定期需要修改密码
            </h3>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="requiredStar">*</span>旧密码</label>
            <div class="layui-input-block">
                <input type="password" id="OldPassword" name="OldPassword" lay-verify="OldPassword" maxlength="18" readonly onfocus="this.removeAttribute('readonly')" autocomplete="off" placeholder="请输入旧密码" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="requiredStar">*</span>新密码</label>
            <div class="layui-input-block">
                <input type="password" id="NewPassword" name="NewPassword" lay-verify="NewPassword" maxlength="18" readonly onfocus="this.removeAttribute('readonly')" autocomplete="off" placeholder="请输入新密码" class="layui-input">
                <img lang="1" id="handelPassword" style="position: absolute;right: 15px;top: 16px;width: 16px;height: 8px;cursor: pointer;" src="~/Content/images/Login/psw0.png" />
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="requiredStar">*</span>重复新密码</label>
            <div class="layui-input-block">
                <input type="password" id="ConfirmPassword" name="ConfirmPassword" lay-verify="ConfirmPassword" maxlength="18" readonly onfocus="this.removeAttribute('readonly')" autocomplete="off" placeholder="请输入重复新密码" class="layui-input">
                <img lang="1" id="handelPasswordRepeat" style="position: absolute;right: 15px;top: 16px;width: 16px;height: 8px;cursor: pointer;" src="~/Content/images/Login/psw0.png" />
                <div style="margin-top: 10px;color: #ff0000;">请输入8-16位字符，至少包含数字、大写字母、小写字母、特殊字符中的三种类型</div>
            </div>
        </div>

        <div class="layui-form-item text-center">
            <button class="layui-btn layui-btn-normal" style="width: 159px;" id="btnSave">修改</button>
        </div>
        <div class="layui-form-item text-center">
            <button type="button" class="layui-btn" style="width: 159px;" id="back">切换账户</button>
        </div>
    </div>
    <script src="~/Content/jquery/jquery.min.js"></script>
    <script src="~/Content/jquery/jquery.md5.min.js"></script>
    <script src="~/Content/layui/layui.all.js"></script>
    <script>

        $(function () {

            $("#handelPassword").click(function(){
                var lang = $(this).attr("lang");
                if (lang == 1) {
                    $(this).attr("lang", "2");
                    $("#NewPassword").attr("type", "text");
                    $(this).attr("src", "/Content/images/Login/psw1.png");
                } else {
                    $(this).attr("lang", "1");
                    $("#NewPassword").attr("type", "password");
                    $(this).attr("src", "/Content/images/Login/psw0.png");
                }
            })

            $("#handelPasswordRepeat").click(function(){
                var lang = $(this).attr("lang");
                if (lang == 1) {
                    $(this).attr("lang", "2");
                    $("#ConfirmPassword").attr("type", "text");
                    $(this).attr("src", "/Content/images/Login/psw1.png");
                } else {
                    $(this).attr("lang", "1");
                    $("#ConfirmPassword").attr("type", "password");
                    $(this).attr("src", "/Content/images/Login/psw0.png");
                }
            })

            $("#btnSave").click(function () {
                var OldPassword = $("#OldPassword").val();
                var NewPassword = $("#NewPassword").val();
                var ConfirmPassword = $("#ConfirmPassword").val();
                if (!OldPassword) {
                    layer.msg("请输入旧密码", { icon: 5 });
                    return false;
                }
                if (!NewPassword) {
                    layer.msg("请输入新密码", { icon: 5 });
                    return false;
                }
                if (!ConfirmPassword) {
                    layer.msg("请输入重复新密码", { icon: 5 });
                    return false;
                }
                if (NewPassword != ConfirmPassword) {
                    layer.msg("两次密码输入不一样", { icon: 5 });
                    return false;
                }

                if (!(/^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z\W_]+$)(?![a-z0-9]+$)(?![a-z\W_]+$)(?![0-9\W_]+$)[a-zA-Z0-9\W_]{8,16}$/.test(NewPassword))) {
                    layer.msg("请输入8-16位字符，至少包含数字、大写字母、小写字母、特殊字符中的三种类型", { icon: 5 });
                    return false;
                }

                layer.confirm('请牢记新设置的密码', function (index) {

                    var postData = {
                        password: $.md5($("#NewPassword").val()),
                        oldPassword: $.md5($("#OldPassword").val())
                    };
                    $.ajax({
                        type: 'POST',
                        url: "/UserCenter/ModifyPassword?" + Math.random(),
                        data: postData,
                        traditional: true,
                        success: function (data) {
                            var dataInfo = JSON.parse(data);
                            if (dataInfo["code"] == 200) {
                                window.location.href = "/Login/Index";
                            } else {
                                layer.msg(dataInfo["info"], { icon: 5 });
                                return false;
                            }
                        },
                        error: function (msg) {
                            layer.msg(msg, { icon: 5 });
                        }, complete: function (data) {
                        }
                    });
                });
            })
            $("#back").click(function () {
                window.location.href = "/Login/Index";
            })
        });
    </script>
</body>
</html>
